enum Color { Red, Green, Blue };

let c: Color = Color.Red
console.log(c);

enum Name { "zheng", "zhang" = 6, "zhou" }

console.log(Name);

// any类型

function fun(obj: string): any {
  return obj
}
console.log(fun("132"));

// 断言
let someValue: any = "this is a string"

// 尖括号型
let strLength: number = (<string>someValue).length

// as类型
let strLength1: number = (someValue as string).length

console.log(strLength, strLength1);


// 数组去重 函数数据类型约束

let arr: number[] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 5, 4, 6, 1, 2, 1, 2, 3, 1, 4, 2]

const findArr = (arr: number[]): number[] => {
  let newArr: number[] = [];
  arr.forEach((item) => {
    if (newArr.indexOf(item) === -1) {
      newArr.push(item)
    }
  })

  return newArr

}

console.log(findArr(arr));

// 定义一个数值和字符串的联合类型
let num: [number, string] = [2, "222"]

// 定义一个类型断言

let Assert: string = "我是郑星辉"
let isAssert: number = (Assert as string).length

// 定义一个vido实现函数的无返回值
function Viods(): void {
  console.log("woshivoid");

}
// 定义一个never的函数
function error(message: string): never {
  throw new Error(message);
}

function fail() {
  return error("Something failed");
}
// 	定义函数时， 分别实现参数类型、剩余参数、默认参数
interface fun {
  name: string,
  age: number,
  sex: string
}








